#include <iostream>
#include <Qt>
#include <QtCore>
// the custom one
#include "camrec.h"

using namespace std;


void parseGetConf(QMap<QString,QString>* conf_params){
    //open here the< file
    QFile myfile(CAM_CONF);
    
    if (myfile.open(QFile::ReadOnly)){
	    //cout << "The conf file opened"<< endl;
	    qint64 lineLength = 1; // something default
	    while (1){
		    char buf[1024];
		    lineLength = myfile.readLine(buf, sizeof(buf));
		    
		    if (lineLength != -1){
       			//do the job
        		// to process it firstly strip the white spaces
        		QString con_var(buf);
        		//cout << "The current line is : "<<con_var.toStdString() << endl;
        		con_var.trimmed();
        		
        		if ((!con_var.startsWith((QString)"#")) && (!(con_var.length()<3))){
				//split the string from x = w 
        			QStringList param_list = con_var.split("=");
        		
        		//cout << "The inner current line is : "<<con_var.toStdString() << endl;
        		//cout << "The inner current line is : "<<con_var.length() << endl;
                  //  for(int i=0;i<param_list.size();i++)
                    //    cout << param_list[i].toStdString()<<endl;

        			if (param_list.isEmpty() || param_list.size()!=2){
        				cout <<"Error in the conf file fix it " << endl;
        				break;
        			}	
        			if (!conf_params->contains((QString)param_list.at(0).trimmed())){
        				cout << "Not known configuration word" << endl;
        				break;
        			}
        			
        			// do the insertion here 
        			//conf_params[(QString)param_list.at(0).trimmed()] =  (QString)param_list.at(1).trimmed();
        			conf_params->insert((QString)(param_list.at(0).trimmed()),(QString)(param_list.at(1).trimmed()));
        			
        		}
        	}
        	else // the end of the file i hope
        		break;
        	 
        	
        }

    
    }
    else // the file openinng error
        cout << "Error in opening the file really !" << CAM_CONF <<endl;	
	
    
}
